package algotithm.jianzhioffer.test53_II;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/10-15:42
 * @Title 剑指 Offer 53 - II. 0～n-1中缺失的数字
 */
public class Solution {

    public static void main(String[] args) {
        int[] nums = {0,1,2,3,4,5,6,7,9};
        Solution solution = new Solution();
        int ans = solution.missingNumber(nums);
        System.out.println(ans);
    }

    public int missingNumber(int[] nums) {
        int i = 0, j = nums.length - 1;
        while (i <= j) {
            int mid = i + (j - i) / 2;
            if (nums[mid] == mid) {
                i = mid + 1;
            } else {
                j = mid - 1;
            }
        }
        return i;
    }
}
